<template>
  <el-select
    v-model="selectedData"
    v-bind="$attrs"
    :filterable="true"
  >
    <el-option
      v-for="(item, index) in list"
      :key="index"
      :value="item.deptId"
      :label="item.deptName"
    />
  </el-select>
</template>

<script>
export default {
  name: 'HospitalSelect',
  props: {
    value: {
      required: true,
    },
  },
  data() {
    return {
      list: [],
    };
  },
  computed: {
    selectedData: {
      set(val) {
        this.$emit('input', val);
        this.$emit('change', val);
      },
      get() {
        return this.value;
      },
    },
    deptCachedList() {
      return this.$store.state['SYSTEM_DEPT'].list;
    },
  },
  created() {
    this.list = this.getList();
  },
  methods: {
    getList() {
      return this.deptCachedList.filter(item => item.deptType !== 0).filter(item => item.parentId === 0);
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
